package src;

public class RockPaperScissors {
	public Result play(RPSEnum p1, RPSEnum p2)
	{
		switch(p1)
		{
		case PAPER:
			switch(p2)
			{
				case PAPER:
					return Result.TIE;					
				case ROCK:
					return Result.WIN;					
				case SCISSORS:
					return Result.LOST;	
				default:
					return Result.TIE;
			}
		case ROCK:
			switch(p2)
			{
				case PAPER:
					return Result.LOST;
				case ROCK:
					return Result.TIE;
				case SCISSORS:
					return Result.WIN;
				default:
					return Result.TIE;
			}
		case SCISSORS:
			switch(p2)
			{
				case PAPER:
					return Result.WIN;
				case ROCK:
					return Result.LOST;
				case SCISSORS:
					return Result.TIE;
				default:
					return Result.TIE;
			}
		default:
				return Result.TIE;
				
		}
	}
	
	public Result play(Player p1, Player p2)
	{
		for(int i = 0 ; i < p1.getRPSEnumLength() ; i++){
			switch(play(p1.getNextMove(), p2.getNextMove()))
			{
				case WIN:
					p1.setScore(p1.getScore() + 1);
					p2.setScore(p2.getScore() - 1);
					System.out.println("WIN");
					break;
				case LOST:
					p1.setScore(p1.getScore() - 1);
					p2.setScore(p2.getScore() + 1);
					System.out.println("LOST");
					break;
				case TIE:
					p1.setScore(p1.getScore() + 1);
					p2.setScore(p2.getScore() + 1);
					System.out.println("TIE");
					break;
				default:
					break;
			}
		}
		
		if(p1.getScore() > p2.getScore()) 
			return Result.WIN;
		else if(p1.getScore() < p2.getScore()) 
			return Result.LOST;
		else return 
				Result.TIE;
	}
}
